package com.zl.learning.db;

import com.github.shyiko.mysql.binlog.BinaryLogClient;
import org.junit.Test;

import java.io.IOException;

/**
 * 测试 解析 MySQL BinLog日志
 */
public class Test1 {

    @Test
    public void test1() throws IOException {
        final BinaryLogClient client = new BinaryLogClient("172.31.4.248", 3306, "root", "*Jsnjcc*");
//        client.setBinlogFilename("mysql-bin.000002");
//        client.setBinlogPosition(123);
        client.registerEventListener(event -> {
            event.getHeader().getEventType();
//            event.getData()
            //Event{header=EventHeaderV4{timestamp=1590486870000, eventType=TABLE_MAP, serverId=1, headerLength=19, dataLength=65, nextPosition=592177047, flags=0}, data=TableMapEventData{tableId=123, database='sc1902', table='tbl_operatelog', columnTypes=15, 15, 15, 15, 15, 15, 18, 15, columnMetadata=150, 150, 150, 765, 150, 150, 0, 150, columnNullability={2, 3, 4, 5, 7}, eventMetadata=TableMapEventMetadata{signedness=null, defaultCharset=33, charsetCollations=null, columnCharsets=null, columnNames=null, setStrValues=null, enumStrValues=null, geometryTypes=null, simplePrimaryKeys=null, primaryKeysWithPrefix=null, enumAndSetDefaultCharset=null, enumAndSetColumnCharsets=null}}}
            System.out.println(event.toString());
            System.out.println(client.getBinlogPosition());
        });
        client.connect();
    }
}
